package com.onlinesys.utils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.onlinesys.database.DBManager;

public class LogUtils {

	public static void logEvent(int type, String msg) {
		Connection conn = null;
		Statement stmt = null;
		try {
			String sql = "INSERT INTO sys_event (event, type, logDate) VALUES ('"
					+ msg
					+ "', "
					+ type
					+ ", '"
					+ OnlineSystemUtils.getCurrentLocalDate() + "')";
			conn = DBManager.getDBConnection();
			stmt = conn.createStatement();
			stmt.execute(sql);
			DBManager.free(null, stmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void logInfo(String msg) {
		Connection conn = null;
		Statement stmt = null;
		try {
			String sql = "INSERT INTO sys_event (event, type, logDate) VALUES ('"
					+ msg
					+ "', 0 , '"
					+ OnlineSystemUtils.getCurrentLocalDate() + "')";
			conn = DBManager.getDBConnection();
			stmt = conn.createStatement();
			stmt.execute(sql);
			DBManager.free(null, stmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void logWarn(String msg) {
		Connection conn = null;
		Statement stmt = null;
		try {
			String sql = "INSERT INTO sys_event (event, type, logDate) VALUES ('"
					+ msg
					+ "', 1 , '"
					+ OnlineSystemUtils.getCurrentLocalDate() + "')";
			conn = DBManager.getDBConnection();
			stmt = conn.createStatement();
			stmt.execute(sql);
			DBManager.free(null, stmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void logError(String msg) {
		Connection conn = null;
		Statement stmt = null;
		try {
			String sql = "INSERT INTO sys_event (event, type, logDate) VALUES ('"
					+ msg
					+ "', 2 , '"
					+ OnlineSystemUtils.getCurrentLocalDate() + "')";
			conn = DBManager.getDBConnection();
			stmt = conn.createStatement();
			stmt.execute(sql);
			DBManager.free(null, stmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
